﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntelligentGateway.Tools
{
    public class AppSettingsTools
    {
        static IConfiguration Configuration { get; set; }
        static string ContentPath = string.Empty;
        public AppSettingsTools(string contentPath)
        {
            string Path = "appsettings.json";
            ContentPath = contentPath;
            Configuration = new ConfigurationBuilder().SetBasePath(contentPath).Add(new JsonConfigurationSource { Path = Path, Optional = false, ReloadOnChange = true }).Build();
        }
        public static string GetContent(params string[] sections)
        {
            try
            {
                if (sections.Any())
                {
                    if (sections.Length == 1)
                    {
                        return Configuration[sections[0]];
                    }
                    else return Configuration[string.Join(":", sections)];
                }
            }
            catch (Exception) { }

            return "";
        }
    }
}
